package com.gjun.struts.action;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.gjun.struts.bean.GjunMainTypeJson2Bean;
import com.gjun.struts.bean.GjunMaintype;
import com.gjun.struts.bean.GjunRoleJsonBean;
import com.gjun.struts.resource.GjunRoleResourceIf;
import com.gjun.struts.util.JSONHelper;
import com.gjun.struts.util.UUIDGenerator;

public class MgrSystemRolesAction {

	private String result;

	private GjunRoleResourceIf roleResource;
	
	private int roleId;
	
	
	private String typename;
	
	private String info;
	
	private File file;

	private String fileFileName;

	private String fileContentType;
	
	private void copy(File src, File dst) {
		try {
			InputStream in = null;
			OutputStream out = null;
			try {
				in = new BufferedInputStream(new FileInputStream(src));
				out = new BufferedOutputStream(new FileOutputStream(dst));
				byte[] buffer = new byte[1024];
				while (in.read(buffer) > 0) {
					out.write(buffer);
				}
			} finally {
				if (null != in) {
					in.close();
				}
				if (null != out) {
					out.close();
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private String getExtention(String fileName) {
		int pos = fileName.lastIndexOf(".");
		return fileName.substring(pos);
	}
	
	

	

	public String loadAllRoles() throws Exception{
		List<GjunRoleJsonBean> beans = roleResource.loadAllRoles();
		try {
			result = JSONHelper.roleToJson(beans);
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return "success";
	}
	
	public String delRole() throws Exception{
		try{
			
			roleResource.delRoleById(roleId);
			result = "delSuccess";
		}catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}
		return "success";
	}
	
	

	
	
	
	public File getFile() {
		return file;
	}

	public void setFile(File file) {
		this.file = file;
	}

	public String getFileContentType() {
		return fileContentType;
	}

	public void setFileContentType(String fileContentType) {
		this.fileContentType = fileContentType;
	}

	public String getFileFileName() {
		return fileFileName;
	}

	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}

	public String getInfo() {
		return info;
	}

	public void setInfo(String info) {
		this.info = info;
	}

	public String getTypename() {
		return typename;
	}

	public void setTypename(String typename) {
		this.typename = typename;
	}

	/**
	 * @return the roleResource
	 */
	public GjunRoleResourceIf getRoleResource() {
		return roleResource;
	}

	/**
	 * @param roleResource the roleResource to set
	 */
	public void setRoleResource(GjunRoleResourceIf roleResource) {
		this.roleResource = roleResource;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}
    
	/**
	 * @return the roleId
	 */
	public int getRoleId() {
		return roleId;
	}

	/**
	 * @param roleId the roleId to set
	 */
	public void setRoleId(int roleId) {
		this.roleId = roleId;
	}

	
}
